package tool;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class GetWeights {
	
	/*Precondition: Set up the path of weights file in the file of Settings.java, in which file only contain numbers.
	 *Postcondition: Return an weights matrix, whose rows and columns are equal to the number of vertexes.
	 */
	public static double[][] getWeights(){
		int[][] adjMatrix = GetAdjMatrix.getAdjMatrix();
		int rows = adjMatrix.length;
		double[][] weightsMatrix = new double[rows][rows];
		
		File weightsFile = new File(Settings.timeFilePath);
		try {
			FileReader fr = new FileReader(weightsFile);
			BufferedReader br = new BufferedReader(fr);
			for(int i = 0; i < rows; i++){
				try {
					String[] arr = br.readLine().split(" ");
					int temp = 0;
					for(int j = 0; j < rows; j++){
						if(adjMatrix[i][j] == 1){
							weightsMatrix[i][j] = Double.parseDouble(arr[temp]);
							temp++;
						}
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return weightsMatrix;
		
	}
}
